//
//  DripViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/6/3.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "DripViewController.h"

@interface DripViewController ()

@end

@implementation DripViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    //设置导航栏头文字
    self.navigationItem.title = @"园内点滴";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#ff763a" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    //自定义左右按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(turntolast)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    [self subView];
    
    
    
    
}
-(void)turntolast{
    
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)subView{
    
    UILabel * testlable = [[UILabel alloc]initWithFrame:CGRectMake(10,20,200,20)];
    NSString * tstring =@"之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法之前实现自适应撑高的方法";
    testlable.numberOfLines =0;
    UIFont * tfont = [UIFont systemFontOfSize:16];
    testlable.font = tfont;
    testlable.lineBreakMode =NSLineBreakByTruncatingTail ;
    testlable.text = tstring ;
    [testlable setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:testlable];
    //高度估计文本大概要显示几行，宽度根据需求自己定义。 MAXFLOAT 可以算出具体要多高
    CGSize size =CGSizeMake(SCREEN_WIDTH-20,MAXFLOAT);
    // label可设置的最大高度和宽度
    //    CGSize size = CGSizeMake(300.f, MAXFLOAT);
    //    获取当前文本的属性
    NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
    //ios7方法，获取文本需要的size，限制宽度
    CGSize  actualsize =[tstring boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;
    // ios7之前使用方法获取文本需要的size，7.0已弃用下面的方法。此方法要求font，与breakmode与之前设置的完全一致
    //    CGSize actualsize = [tstring sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
    //   更新UILabel的frame
    testlable.frame =CGRectMake(10,140, actualsize.width, actualsize.height);
    [self.view addSubview:testlable];
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
